﻿using Microsoft.Win32;
using PropertyCreator.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PropertyCreator
{
   public static  class Code
    {
       static string RegisterBasePath = Environment.Is64BitOperatingSystem ?
           @"SOFTWARE\Wow6432Node\Mysoft" : @"SOFTWARE\Mysoft";
       public static List<string> GetRegisterNameList()
       {
           try
           {
               return Registry.LocalMachine.OpenSubKey(RegisterBasePath).GetSubKeyNames().ToList();
           }
           catch
           {
               return new List<string>();
           }
       }

       public static DBInfoModel GetDBInfo(string registerName)
       {
           RegistryKey regKey = Registry.LocalMachine.OpenSubKey(RegisterBasePath + "\\" + registerName);
           return (string.IsNullOrWhiteSpace(registerName) || regKey == null)
               ? new DBInfoModel()
               {
                   Register = registerName
               }
               : new DBInfoModel()
               {
                   Register = registerName,
                   Address = regKey.GetValue("ServerName").ToString(),
                   DBName = regKey.GetValue("DBName").ToString(),
                   UserName = regKey.GetValue("UserName").ToString(),
                   Passoword = regKey.GetValue("SaPassword").ToString()
               };
       }
    }
}
